package com.kgc.scd.controller;

import com.kgc.scd.bean.Comment;
import com.kgc.scd.form.CommentForm;
import com.kgc.scd.form.ReviewForm;
import com.kgc.scd.service.WebCommentService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.ResultBuildUtil;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created On : 2022/11/17.
 * <p>
 * Author : #jiangguoqiang
 * <p>
 * Description: WebCommentController
 */
@Slf4j
@RestController
@Api(tags = "16、评论入口(jgq)",value = "对已收货的订单可以进行首评和追评")
public class WebCommentController {
    @Autowired
    private WebCommentService webCommentService;
    /**
     * @author : Administrator
     * @date   : 2022/11/15
     * @param  : [comment, pageNo, pageSize]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 查询评论列表
     */
    @ApiOperation(value = "查询评论表",notes = "根据商品id来查询评论表")
    @GetMapping("/getCommentList")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<PageSupport<Comment>> getCommentList(@ApiParam(name = "goodsId",value = "商品id") @RequestParam(required = false) String goodsId,
                                                              @ApiParam(required = true,name = "pageNo",value = "当前页") @RequestParam(value="pageNo",defaultValue="1") Integer pageNo,
                                                              @ApiParam(required = true,name = "pageSize",value = "条数") @RequestParam(value = "pageSize", defaultValue = "3") Integer pageSize){

        PageSupport<Comment>  support = webCommentService.getCommentList(goodsId,pageNo, pageSize);
        return ResultBuildUtil.success(support);
    }

    /**
     * @author : Administrator
     * @date   : 2022/11/15
     * @param  : [comment]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 增加评论
     */
    @ApiOperation(value = "增加评论",notes = "将订单状态6已签收改为订单状态7已评论")
    @PostMapping("/addCommentList")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<?> addCommentList(@RequestBody CommentForm commentForm){
        return webCommentService.addCommentList(commentForm);
    }

    /**
     * @author : Administrator
     * @date   : 2022/11/15
     * @param  : [reviewForm]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 追加评论
     */
    @ApiOperation(value = "追加评论",notes = "将订单状态7已评论改为订单状态8已追评价")
    @PostMapping("/updateReviewList")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 999,message = "失败")
    })
    public RequestResult<?> addReviewList(@RequestBody ReviewForm reviewForm){
        return webCommentService.addReviewList(reviewForm);
    }
}
